<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD><TITLE>Tcl_IntObj manual page - Tcl Library Procedures</TITLE>
<link rel="stylesheet" href="../docs.css" type="text/css" media="all">
</HEAD>
<BODY><H2><a href="../contents.htm">Tcl8.6.11/Tk8.6.11 Documentation</a> <small>&gt;</small> <a href="contents.htm">Tcl C API</a> <small>&gt;</small> IntObj</H2>
<H3><A HREF="../UserCmd/contents.htm">Tcl/Tk Applications</A> | <A HREF="../TclCmd/contents.htm">Tcl Commands</A> | <A HREF="../TkCmd/contents.htm">Tk Commands</A> | <A HREF="../ItclCmd/contents.htm">[incr Tcl] Package Commands</A> | <A HREF="../SqliteCmd/contents.htm">SQLite3 Package Commands</A> | <A HREF="../TdbcCmd/contents.htm">TDBC Package Commands</A> | <A HREF="../TdbcmysqlCmd/contents.htm">tdbc::mysql Package Commands</A> | <A HREF="../TdbcodbcCmd/contents.htm">tdbc::odbc Package Commands</A> | <A HREF="../TdbcpostgresCmd/contents.htm">tdbc::postgres Package Commands</A> | <A HREF="../TdbcsqliteCmd/contents.htm">tdbc::sqlite3 Package Commands</A> | <A HREF="../ThreadCmd/contents.htm">Thread Package Commands</A> | <A HREF="../TclLib/contents.htm">Tcl C API</A> | <A HREF="../TkLib/contents.htm">Tk C API</A> | <A HREF="../ItclLib/contents.htm">[incr Tcl] Package C API</A> | <A HREF="../TdbcLib/contents.htm">TDBC Package C API</A></H3>
<DL>
<DD><A HREF="IntObj.htm#M2" NAME="L430">NAME</A>
<DL><DD>Tcl_NewIntObj, Tcl_NewLongObj, Tcl_NewWideIntObj, Tcl_SetIntObj, Tcl_SetLongObj, Tcl_SetWideIntObj, Tcl_GetIntFromObj, Tcl_GetLongFromObj, Tcl_GetWideIntFromObj, Tcl_NewBignumObj, Tcl_SetBignumObj, Tcl_GetBignumFromObj, Tcl_TakeBignumFromObj &mdash; manipulate Tcl values as integers</DD></DL>
<DD><A HREF="IntObj.htm#M3" NAME="L431">SYNOPSIS</A>
<DL>
<DD><B>#include &lt;tcl.h&gt;</B>
<DD>Tcl_Obj *
<DD><B>Tcl_NewIntObj</B>(<I>intValue</I>)
<DD>Tcl_Obj *
<DD><B>Tcl_NewLongObj</B>(<I>longValue</I>)
<DD>Tcl_Obj *
<DD><B>Tcl_NewWideIntObj</B>(<I>wideValue</I>)
<DD><B>Tcl_SetIntObj</B>(<I>objPtr, intValue</I>)
<DD><B>Tcl_SetLongObj</B>(<I>objPtr, longValue</I>)
<DD><B>Tcl_SetWideIntObj</B>(<I>objPtr, wideValue</I>)
<DD>int
<DD><B>Tcl_GetIntFromObj</B>(<I>interp, objPtr, intPtr</I>)
<DD>int
<DD><B>Tcl_GetLongFromObj</B>(<I>interp, objPtr, longPtr</I>)
<DD>int
<DD><B>Tcl_GetWideIntFromObj</B>(<I>interp, objPtr, widePtr</I>)
<DD><B>#include &lt;tclTomMath.h&gt;</B>
<DD>Tcl_Obj *
<DD><B>Tcl_NewBignumObj</B>(<I>bigValue</I>)
<DD><B>Tcl_SetBignumObj</B>(<I>objPtr, bigValue</I>)
<DD>int
<DD><B>Tcl_GetBignumFromObj</B>(<I>interp, objPtr, bigValue</I>)
<DD>int
<DD><B>Tcl_TakeBignumFromObj</B>(<I>interp, objPtr, bigValue</I>)
<DD>int
<DD><B>Tcl_InitBignumFromDouble</B>(<I>interp, doubleValue, bigValue</I>)
</DL>
<DD><A HREF="IntObj.htm#M4" NAME="L432">ARGUMENTS</A>
<DL class="arguments">
</DL>
<DD><A HREF="IntObj.htm#M5" NAME="L433">DESCRIPTION</A>
<DD><A HREF="IntObj.htm#M6" NAME="L434">SEE ALSO</A>
<DD><A HREF="IntObj.htm#M7" NAME="L435">KEYWORDS</A>
</DL>
<H3><A NAME="M2">NAME</A></H3>
Tcl_NewIntObj, Tcl_NewLongObj, Tcl_NewWideIntObj, Tcl_SetIntObj, Tcl_SetLongObj, Tcl_SetWideIntObj, Tcl_GetIntFromObj, Tcl_GetLongFromObj, Tcl_GetWideIntFromObj, Tcl_NewBignumObj, Tcl_SetBignumObj, Tcl_GetBignumFromObj, Tcl_TakeBignumFromObj &mdash; manipulate Tcl values as integers
<H3><A NAME="M3">SYNOPSIS</A></H3>
<B>#include &lt;tcl.h&gt;</B><BR>
<A HREF="../TclLib/Object.htm">Tcl_Obj</A> *<BR>
<B>Tcl_NewIntObj</B>(<I>intValue</I>)<BR>
<A HREF="../TclLib/Object.htm">Tcl_Obj</A> *<BR>
<B>Tcl_NewLongObj</B>(<I>longValue</I>)<BR>
<A HREF="../TclLib/Object.htm">Tcl_Obj</A> *<BR>
<B>Tcl_NewWideIntObj</B>(<I>wideValue</I>)<BR>
<B>Tcl_SetIntObj</B>(<I>objPtr, intValue</I>)<BR>
<B>Tcl_SetLongObj</B>(<I>objPtr, longValue</I>)<BR>
<B>Tcl_SetWideIntObj</B>(<I>objPtr, wideValue</I>)<BR>
int<BR>
<B>Tcl_GetIntFromObj</B>(<I>interp, objPtr, intPtr</I>)<BR>
int<BR>
<B>Tcl_GetLongFromObj</B>(<I>interp, objPtr, longPtr</I>)<BR>
int<BR>
<B>Tcl_GetWideIntFromObj</B>(<I>interp, objPtr, widePtr</I>)<BR>
<B>#include &lt;tclTomMath.h&gt;</B><BR>
<A HREF="../TclLib/Object.htm">Tcl_Obj</A> *<BR>
<B>Tcl_NewBignumObj</B>(<I>bigValue</I>)<BR>
<B>Tcl_SetBignumObj</B>(<I>objPtr, bigValue</I>)<BR>
int<BR>
<B>Tcl_GetBignumFromObj</B>(<I>interp, objPtr, bigValue</I>)<BR>
int<BR>
<B>Tcl_TakeBignumFromObj</B>(<I>interp, objPtr, bigValue</I>)<BR>
int<BR>
<B>Tcl_InitBignumFromDouble</B>(<I>interp, doubleValue, bigValue</I>)<BR>
<H3><A NAME="M4">ARGUMENTS</A></H3>
<DL class="arguments">
<DT>int <B>intValue</B> (in)<DD>
Integer value used to initialize or set a Tcl value.
<P><DT>long <B>longValue</B> (in)<DD>
Long integer value used to initialize or set a Tcl value.
<P><DT>Tcl_WideInt <B>wideValue</B> (in)<DD>
Wide integer value used to initialize or set a Tcl value.
<P><DT><A HREF="../TclLib/Object.htm">Tcl_Obj</A> <B>*objPtr</B> (in/out)<DD>
For <B>Tcl_SetIntObj</B>, <B>Tcl_SetLongObj</B>, <B>Tcl_SetWideIntObj</B>,
and <B>Tcl_SetBignumObj</B>, this points to the value in which to store an
integral value.  For <B>Tcl_GetIntFromObj</B>, <B>Tcl_GetLongFromObj</B>,
<B>Tcl_GetWideIntFromObj</B>, <B>Tcl_GetBignumFromObj</B>, and
<B>Tcl_TakeBignumFromObj</B>, this refers to the value from which
to retrieve an integral value.
<P><DT><A HREF="../TclLib/Interp.htm">Tcl_Interp</A> <B>*interp</B> (in/out)<DD>
When non-NULL, an error message is left here when integral value
retrieval fails.
<P><DT>int <B>*intPtr</B> (out)<DD>
Points to place to store the integer value retrieved from <I>objPtr</I>.
<P><DT>long <B>*longPtr</B> (out)<DD>
Points to place to store the long integer value retrieved from <I>objPtr</I>.
<P><DT>Tcl_WideInt <B>*widePtr</B> (out)<DD>
Points to place to store the wide integer value retrieved from <I>objPtr</I>.
<P><DT>mp_int <B>*bigValue</B> (in/out)<DD>
Points to a multi-precision integer structure declared by the LibTomMath
library.
<P><DT>double <B>doubleValue</B> (in)<DD>
Double value from which the integer part is determined and
used to initialize a multi-precision integer value.
<P></DL>
<H3><A NAME="M5">DESCRIPTION</A></H3>
These procedures are used to create, modify, and read Tcl values
that hold integral values.
<P>
The different routines exist to accommodate different integral types in C
with which values might be exchanged.  The C integral types for which Tcl
provides value exchange routines are <B>int</B>, <B>long int</B>,
<B>Tcl_WideInt</B>, and <B>mp_int</B>.  The <B>int</B> and <B>long int</B> types
are provided by the C language standard.  The <B>Tcl_WideInt</B> type is a
typedef defined to be whatever signed integral type covers at least the
64-bit integer range (-9223372036854775808 to 9223372036854775807).  Depending
on the platform and the C compiler, the actual type might be
<B>long int</B>, <B>long long int</B>, <B>__int64</B>, or something else.
The <B>mp_int</B> type is a multiple-precision integer type defined
by the LibTomMath multiple-precision integer library.
<P>
The <B>Tcl_NewIntObj</B>, <B>Tcl_NewLongObj</B>, <B>Tcl_NewWideIntObj</B>,
and <B>Tcl_NewBignumObj</B> routines each create and return a new
Tcl value initialized to the integral value of the argument.  The
returned Tcl value is unshared.
<P>
The <B>Tcl_SetIntObj</B>, <B>Tcl_SetLongObj</B>, <B>Tcl_SetWideIntObj</B>,
and <B>Tcl_SetBignumObj</B> routines each set the value of an existing
Tcl value pointed to by <I>objPtr</I> to the integral value provided
by the other argument.  The <I>objPtr</I> argument must point to an
unshared Tcl value.  Any attempt to set the value of a shared Tcl value
violates Tcl's copy-on-write policy.  Any existing string representation
or internal representation in the unshared Tcl value will be freed
as a consequence of setting the new value.
<P>
The <B>Tcl_GetIntFromObj</B>, <B>Tcl_GetLongFromObj</B>,
<B>Tcl_GetWideIntFromObj</B>, <B>Tcl_GetBignumFromObj</B>, and
<B>Tcl_TakeBignumFromObj</B> routines attempt to retrieve an integral
value of the appropriate type from the Tcl value <I>objPtr</I>.  If the
attempt succeeds, then <B><A HREF="../TclCmd/catch.htm">TCL_OK</A></B> is returned, and the value is
written to the storage provided by the caller.  The attempt might
fail if <I>objPtr</I> does not hold an integral value, or if the
value exceeds the range of the target type.  If the attempt fails,
then <B><A HREF="../TclCmd/catch.htm">TCL_ERROR</A></B> is returned, and if <I>interp</I> is non-NULL,
an error message is left in <I>interp</I>.  The <B><A HREF="../TclLib/ObjectType.htm">Tcl_ObjType</A></B>
of <I>objPtr</I> may be changed to make subsequent calls to the
same routine more efficient. Unlike the other functions,
<B>Tcl_TakeBignumFromObj</B> may set the content of the Tcl value
<I>objPtr</I> to an empty string in the process of retrieving the
multiple-precision integer value.
<P>
The choice between <B>Tcl_GetBignumFromObj</B> and
<B>Tcl_TakeBignumFromObj</B> is governed by how the caller will
continue to use <I>objPtr</I>.  If after the <B>mp_int</B> value
is retrieved from <I>objPtr</I>, the caller will make no more
use of <I>objPtr</I>, then using <B>Tcl_TakeBignumFromObj</B>
permits Tcl to detect when an unshared <I>objPtr</I> permits the
value to be moved instead of copied, which should be more efficient.
If anything later in the caller requires
<I>objPtr</I> to continue to hold the same value, then
<B>Tcl_GetBignumFromObj</B> must be chosen.
<P>
The <B>Tcl_InitBignumFromDouble</B> routine is a utility procedure
that extracts the integer part of <I>doubleValue</I> and stores that
integer value in the <B>mp_int</B> value <I>bigValue</I>.
<H3><A NAME="M6">SEE ALSO</A></H3>
<B><A HREF="../TclLib/Object.htm">Tcl_NewObj</A></B>, <B><A HREF="../TclLib/Object.htm">Tcl_DecrRefCount</A></B>, <B><A HREF="../TclLib/Object.htm">Tcl_IncrRefCount</A></B>, <B><A HREF="../TclLib/SetResult.htm">Tcl_GetObjResult</A></B>
<H3><A NAME="M7">KEYWORDS</A></H3>
<A href="../Keywords/I.htm#integer">integer</A>, <A href="../Keywords/I.htm#integer value">integer value</A>, <A href="../Keywords/I.htm#integer type">integer type</A>, <A href="../Keywords/I.htm#internal representation">internal representation</A>, <A href="../Keywords/V.htm#value">value</A>, <A href="../Keywords/V.htm#value type">value type</A>, <A href="../Keywords/S.htm#string representation">string representation</A>
<div class="copy">Copyright &copy; 1996-1997 Sun Microsystems, Inc.
</div>
</BODY></HTML>
